package com.base2.webshop.client.views;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.base2.webshop.client.presenters.MainPresenter;
import com.base2.webshop.client.uihandlers.MainUiHandlers;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import com.gwtplatform.mvp.client.ViewImpl;
import com.gwtplatform.mvp.client.ViewWithUiHandlers;

public class MainView extends ViewWithUiHandlers<MainUiHandlers> implements
		MainPresenter.IMainView {

	final Widget widget;
	
	@UiField
	Button testButton;

	public interface Binder extends UiBinder<Widget, MainView> {
	}

	@Inject
	public MainView(Binder binder) {
		widget = binder.createAndBindUi(this);
	}

	@Override
	public Widget asWidget() {
		return widget;
	}

	@Override
	public void setInSlot(Object slot, Widget content) {
		if (slot == MainPresenter.LOGIN_SLOT_TYPE)
			RootPanel.get("gwt-login").add(content);
		else if (slot == MainPresenter.SEARCH_SLOT_TYPE)
			RootPanel.get("gwt-searchmini").add(content);
		else if (slot == MainPresenter.PRODUCT_DETAIL_SLOT_TYPE)
			RootPanel.get("gwt-productdetail").add(content);
		else
			RootPanel.get().add(null);
	}
	
	@UiHandler("testButton")
	public void testButtonClick(ClickEvent event){
		getUiHandlers().doSomething();
	}

}
